/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Linker;

import java.io.FileNotFoundException;
import java.io.PrintStream;

/**
 *
 * @author Kyle
 */
public class LinkerMain
{
    public static final int VERSION = 1;
    public static void main(String[] args)
    {
        if (args.length == 0)
        {
            System.out.println("Please enter at least one file name");
        }
        else
        {
            Linker linker = new Linker();
            String outputFile = "out.txt";
            for (int i=0; i < args.length; i++)
            {
                if (args[i].equals("-o"))
                {
                    outputFile = args[i+1];
                    i++;
                }
                else
                {
                    linker.AddInput(args[i]);
                }
            }
            linker.PrintSymbols();
            linker.ComputeOutput();
            linker.PrintDump();
            linker.Output.PrintToFile(System.out);
            try
            {
                linker.Output.PrintToFile(new PrintStream(outputFile));
            }
            catch (FileNotFoundException ex)
            {
                System.out.println("Unable to output to file: " + outputFile);
            }
        }
        
    }
}
